def modules():
    '''6. 模块'''
    print('6. 模块')
    from . import fibo
    fibo.fib(1000)
    print('fib name:', fibo.__name__)
    _more_on_modules()
    _standard_modules()
    _dir_function()
    _packages()


def _more_on_modules():
    def __executing_modules_as_scripts():
        print('6.1.1 以脚本方式执行模块')

    def __the_module_search_path():
        print('6.1.2 模块搜索路径')

    def __compiled_python_files():
        print('6.1.3. “已编译的” Python 文件')

    print('6.1.模块详解')
    # 方式1
    from .fibo import fib, fib2
    fib(500)
    fib2(500)
    # 方式2
    # from fibo import *
    # 方式3
    import tutorial.chapter06.fibo as fibo2
    fibo2.fib(500)
    # 方式4
    from .fibo import fib as fibonacci
    fibonacci(500)
    __executing_modules_as_scripts()
    __the_module_search_path()
    __compiled_python_files()


def _standard_modules():
    print('6.2. 标准模块')
    import sys
    # print(sys.ps1)
    # print(sys.ps2)
    sys.path.append('\\ufs\\guido\\lib\\python')
    print('sys.path:', sys.path)


def _dir_function():
    print('6.3. dir() 函数')
    from . import fibo
    import sys
    print('fibo dir:', dir(fibo))
    print('sys dir:', dir(sys))
    print('current dir:', dir())
    import builtins
    print('builtins dir:', dir(builtins))


def _packages():
    def _importing_from_a_package():
        print('6.4.1. 从包中导入 *')
        from .a_package import reverse
        result = reverse('abc')
        print('reverse:', result)

    def _relative_import_package():
        print('6.4.2. 相对导入')
        from . import sound
        print('sound name:', sound.__name__)
        from .. import chapter06
        print('chapter06:', chapter06)
        from ..chapter06 import modules
        print('chapter06 modules:', modules)

    def _packages_in_multiple_directories():
        print('6.4.3.多目录中的包')
        print('package path:', __path__)

    print('6.4. 包')
    # 方式1
    import tutorial.chapter06.sound.effects.echo
    input = 'a.mp3'
    output = 'b.flv'
    tutorial.chapter06.sound.effects.echo.echofilter(
        input, output, delay=0.7, atten=4)
    # 方式2
    from .sound.effects import echo
    input = 'a.mp3'
    output = 'b.flv'
    echo.echofilter(input, output, delay=0.7, atten=4)
    # 方式3
    from .sound.effects.echo import echofilter
    input = 'a.mp3'
    output = 'b.flv'
    echofilter(input, output, delay=0.7, atten=4)
    _importing_from_a_package()
    _relative_import_package()
    _packages_in_multiple_directories()
